package cn.wolfcode.wms.controller;

import cn.wolfcode.wms.domain.OrderBill;
import cn.wolfcode.wms.qo.OrderBillQueryObject;
import cn.wolfcode.wms.qo.QueryObject;
import cn.wolfcode.wms.service.IOrderBillService;
import cn.wolfcode.wms.service.ISupplierService;
import cn.wolfcode.wms.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/orderBill")
public class OrderBillController {

    @Autowired
    private IOrderBillService orderBillService;
    @Autowired
    private ISupplierService supplierService;

    @RequestMapping("/list")
    @RequiredPermission("采购订单列表")
    public String list(OrderBillQueryObject qo, Map map) {
        map.put("pageResult", orderBillService.query(qo));
        return "orderBill/list";
    }

    @RequestMapping("/input")
    @RequiredPermission("采购订单编辑")
    public String input(Long id, Map map) {
        map.put("suppliers", supplierService.listAll());
        if (id != null) {
            map.put("orderBill", orderBillService.getById(id));
        }
        return "orderBill/input";
    }

    @RequestMapping("/saveOrUpdate")
    @RequiredPermission("更新或新增采购订单")
    public String saveOrUpdate(OrderBill orderBill) {
        try {
            orderBillService.saveOrUpdate(orderBill);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "redirect:/orderBill/list.do";
    }

    @RequestMapping("/delete")
    @RequiredPermission("删除采购订单")
    public String delete(Long id) {
        orderBillService.delete(id);
        return "redirect:/orderBill/list.do";
    }
}
